<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>官网网站分类管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">分类管理</div>
                <div class="layui-card-body">
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-group">
                            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                            <button class="layui-btn layui-btn-sm" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</button>
                        </div>
                    </script>
                    <table class="layui-hide" id="column-treetable" lay-filter="column-treetable"></table>
                    <script type="text/html" id="column-table-setTpl">
                        <a class="layui-btn layui-btn-xs"><i class="layui-icon layui-icon-list"></i>类目内容</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="/member/column/edit.do?siteid=${siteId!}&id={{ d.id }}" lay-text="修改分类"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        <a class="layui-btn layui-btn-xs" lay-href="/member/column/add.do?siteid=${siteId!}&parentId={{ d.id }}" lay-text="添加{{ d.columnTitle }}子分类"><i class="layui-icon layui-icon-add-1"></i>添加子类</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
<script>
    layui.config({
        base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
    }).extend({
        treetable: '../layui/treetable-lay/treetable',
        index: 'lib/index' //主入口模块
    }).use(['index','treetable', 'table',  'form'], function () {
        var table = layui.table
            , layer = layui.layer
            , form = layui.form
            , $ = layui.$
            , treetable = layui.treetable;
        //渲染表格
        var renderTable = function () {
            layer.load(2);
            treetable.render({
                id: 'column-treetable',
                treeColIndex: 1,	//树形图标显示在第几列
                treeSpid: '0',		//最上级的父级id
                treeIdName: 'id',	//id字段的名称
                treePidName: 'parentId',	//pid字段的名称，父级菜单id
                treeDefaultClose: true,	//是否默认折叠
                treeLinkage: false,		//父级展开时是否自动展开所有子级
                elem: '#column-treetable',	//表格id
                url: '/admin/system_column/listData.do?siteId=${siteId!}',
                toolbar: '#toolbar',
                page: false,
                cellMinWidth: 120,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'columnTitle', title: '分类名称'},
                    {field: 'sortOrder', title: '排序', width: 120},
                    {fixed: 'right', align: 'center', title: '操作', toolbar: '#column-table-setTpl', width: 320}
                ]],
                //数据渲染完的回调
                done: function () {
                    //关闭加载
                    layer.closeAll('loading');
                }
            })
        };
        renderTable();

        $('.layui-btn .layuiadmin-btn-admin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        table.on('toolbar', function(obj){
            var checkStatus = table.checkStatus('column-treetable');
            var data = checkStatus.data;
            if(obj.event === 'add') {
                if (data.length > 1) {
                    layer.msg("请选择一行作为父级菜单");
                } else {
                    var id = data.length == 1 ? data[0].id : 0;

                    parent.layui.index.openTabsPage("/admin/system_column/add.do?siteId=${siteId!}&parentId=" + id,"添加菜单");
                    /*layer.open({
                        type: 2
                        , title: '添加角色'
                        , content: "/admin/system_column/add.do?siteId=${siteId!}&parentId=" + id
                        , maxmin: true
                        , area: ['500px', '450px']
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , submitID = 'LAY-user-front-submit'
                                , submit = layero.find('iframe').contents().find('#' + submitID);

                            //监听提交
                            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                                //提交 Ajax 成功后，静态更新表格中的数据
                                $.ajax({
                                    url: '/admin/system_column/add.do',
                                    type: 'post',
                                    dataType: 'json',
                                    data: data.field,
                                    success: function (e) {
                                        if (e.code == "0") {
                                            layer.msg('成功');
                                            renderTable();
                                        } else {
                                            layer.msg(e.message);
                                            return;
                                        }
                                    }
                                })
                                layer.close(index); //关闭弹层
                            });

                            submit.trigger('click');
                        }
                    });*/
                    // })
                }
            }else if(obj.event === "delete"){
                if(data.length != 1){
                    layer.msg("请选择一行进行删除！");
                }else{
                    var id = data[0].id;
                    layer.confirm('真的删除选定行的数据吗?', function(index){
                        $.post('/admin/system_column/del.do',{id:id},function(result){
                            if(result.success){
                                layer.close(index);
                                renderTable();
                            }
                            layer.msg(result.msg);
                        });
                    });
                }
            }
        })
    });
</script>
</body>
</html>